package com.ethink.warehouse.facade.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ethink.framework.common.constant.CommonRespCode;
import com.ethink.framework.common.exception.BusinessException;
import com.ethink.warehouse.api.LogisticsTraceApplyOrderFacade;
import com.ethink.warehouse.api.request.*;
import com.ethink.warehouse.api.response.*;
import com.ethink.warehouse.common.mapper.LogisticsTraceApplyDetailOrderMapper;
import com.ethink.warehouse.common.mapper.LogisticsTraceApplyOrderMapper;
import com.ethink.warehouse.service.LogisticsTraceApplyOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 物流跟进申请表 Facade接口实现
 *
 * @author default
 * @date 2022-12-15
 */
@RestController
@Slf4j
@RequestMapping("warehouse-service/facade/v1/logisticsTraceApplyOrder")
public class LogisticsTraceApplyOrderFacadeImpl implements LogisticsTraceApplyOrderFacade {

    @Autowired
    private LogisticsTraceApplyOrderService logisticsTraceApplyOrderService;

    @Autowired
    private LogisticsTraceApplyDetailOrderMapper logisticsTraceApplyDetailOrderMapper;

    @Autowired
    private LogisticsTraceApplyOrderMapper logisticsTraceApplyOrderMapper;

    @Override
    public Page<LogisticsTraceApplyOrderQueryResponse> queryLogisticsTraceApplyOrder(LogisticsTraceApplyOrderQueryRequest request) {
        return logisticsTraceApplyOrderService.queryLogisticsTraceApplyOrder(request);
    }

    @Override
    public List<LogisticsTraceApplyOrderQueryResponse> listLogisticsTraceApplyOrder(LogisticsTraceApplyOrderListRequest request) {
        return logisticsTraceApplyOrderService.listLogisticsTraceApplyOrder(request);
    }

    @Override
    public LogisticsTraceApplyOrderGetDetailResponse getLogisticsTraceApplyOrderById(Long logisticsTraceApplyOrderId) {
        return logisticsTraceApplyOrderService.getLogisticsTraceApplyOrderById(logisticsTraceApplyOrderId);
    }

    @Override
    public LogisticsTraceApplyAddResponse addLogisticsTraceApplyOrder(LogisticsTraceApplyAddRequest addRequest) {
        return logisticsTraceApplyOrderService.addLogisticsTraceApplyOrder(addRequest);
    }

    @Override
    public LogisticsTraceApplyAddResponse updateLogisticsTraceApplyOrder(LogisticsTraceApplyUpdateRequest updateRequest) {
        return logisticsTraceApplyOrderService.updateLogisticsTraceApplyOrder(updateRequest);
    }

    @Override
    public List<LogisticsTraceApplyDetailOrderGetDetailResponse> listLogisticsTraceApplyDetailOrder(LogisticsTraceApplyDetailListRequest request) {
        return logisticsTraceApplyDetailOrderMapper.listLogisticsTraceApplyDetailOrder(request);
    }

    @Override
    public List<LogisticsTraceOrderNoOrderDetailResponse> listLogisticsTraceOrderNoOrderDetail(LogisticsTraceOrderTypeOrderListRequest request) {
        return logisticsTraceApplyOrderService.listLogisticsTraceOrderNoOrderDetail(request);
    }

    @Override
    public void deleteLogisticsTraceApply(LogisticsTraceApplyDeleteRequest request) {
        int ct = logisticsTraceApplyOrderMapper.countTracing(request);
        if (ct > 0) {
            throw new BusinessException(CommonRespCode.SYSTEM_ERR, "当前有正在跟进物流单，不能撤销");
        }
        logisticsTraceApplyOrderMapper.deleteApply(request);
    }

    @Override
    public List<String> queryLogisticsTraceApplyTraceing(LogisticsTraceApplyTraceingQueryRequest request) {
        return logisticsTraceApplyOrderMapper.queryLogisticsTraceApplyTraceing(request);
    }

}